package com.cu.employmentmanagementsystem.util;

import com.cu.employmentmanagementsystem.common.result.MockMultipartFile;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;


public class FileConvertUtils
{
    public static MultipartFile fileConvertToMultipartFile(File file)
    {
        MultipartFile result = null;
        if (null != file)
        {
            try (FileInputStream input = new FileInputStream(file))
            {
                result = new MockMultipartFile(file.getName(), file.getName(), "pdf", input);
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return result;
    }

    public static MultipartFile fileConvertToMultipartFile(File file, String suffix)
    {
        MultipartFile result = null;
        if (null != file)
        {
            try (FileInputStream input = new FileInputStream(file))
            {
                result = new MockMultipartFile(file.getName(), file.getName(), suffix, input);
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return result;
    }
}
